package com.luyuan.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.luyuan.common.annotation.Log;
import com.luyuan.common.core.controller.BaseController;
import com.luyuan.common.core.domain.AjaxResult;
import com.luyuan.common.core.domain.entity.WxappUser;
import com.luyuan.common.enums.BusinessType;
import com.luyuan.system.service.IWxappUserService;
import com.luyuan.common.utils.poi.ExcelUtil;
import com.luyuan.common.core.page.TableDataInfo;

/**
 * 微信小程序用户信息Controller
 * 
 * @author luyuan
 * @date 2025-11-14
 */
@RestController
@RequestMapping("/system/wxappUser")
public class WxappUserController extends BaseController {
    @Autowired
    private IWxappUserService wxappUserService;

    /**
     * 查询微信小程序用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:wxappUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxappUser wxappUser) {
        startPage();
        List<WxappUser> list = wxappUserService.selectWxappUserList(wxappUser);
        return getDataTable(list);
    }

    /**
     * 导出微信小程序用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:wxappUser:export')")
    @Log(title = "微信小程序用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxappUser wxappUser) {
        List<WxappUser> list = wxappUserService.selectWxappUserList(wxappUser);
        ExcelUtil<WxappUser> util = new ExcelUtil<WxappUser>(WxappUser.class);
        util.exportExcel(response, list, "微信小程序用户信息数据");
    }

    /**
     * 获取微信小程序用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wxappUser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(wxappUserService.selectWxappUserByUserId(userId));
    }

    /**
     * 新增微信小程序用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:wxappUser:add')")
    @Log(title = "微信小程序用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxappUser wxappUser) {
        return toAjax(wxappUserService.insertWxappUser(wxappUser));
    }

    /**
     * 修改微信小程序用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:wxappUser:edit')")
    @Log(title = "微信小程序用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxappUser wxappUser) {
        return toAjax(wxappUserService.updateWxappUser(wxappUser));
    }

    /**
     * 删除微信小程序用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:wxappUser:remove')")
    @Log(title = "微信小程序用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(wxappUserService.deleteWxappUserByUserIds(userIds));
    }
}
